package com.bangbang.blog.controller;


import com.bangbang.blog.pojo.TbClassify;
import com.bangbang.blog.service.impl.TbClassifyServiceImpl;
import com.bangbang.configresult.Result;
import com.bangbang.configresult.ResultEnum;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-08-11
 */
@RestController
@RequestMapping("/blog/tbClassify")
public class TbClassifyController {

    @Autowired
    private TbClassifyServiceImpl tbClassifyService;

    //新增
    @PostMapping
    @ApiOperation("课程分类添加方法")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "tbClassify",value = "课程分类实体类",readOnly = true,paramType = "body"),
    })
    public Result insert(@RequestBody TbClassify tbClassify){
        tbClassifyService.insert(tbClassify);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    //修改
    @PutMapping
    @ApiOperation("课程分类修改方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tbClassify",value = "课程分类实体类",readOnly = true,paramType = "body")
    })
    public Result update(@RequestBody TbClassify tbClassify){
        tbClassifyService.updateById(tbClassify);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    //删除
    @DeleteMapping
    @ApiOperation("课程分类删除方法")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "claId",value = "分类id",readOnly = true,paramType = "query")
    })
    public Result delete(@RequestParam(required = true)Long claId){
        tbClassifyService.delete(claId);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    //查询
    @GetMapping
    @ApiOperation("课程分类查询方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "claId",value = "分类Id",required = true,paramType = "query")
    })
    public Result select(@RequestParam(required = false)Long claId){
        tbClassifyService.select(claId);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
}

